<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head th:replace="dashboard/header :: header"></head>
<body class="gray-bg">

<!--
@desc  管理
@author WeiXiaoJin
@since 2019-11-21 07:41:47
-->

	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="operlog-form">
					<div class="select-list">
						<ul>
						<li><label> 任务名称 </label><input type="text" name="condition[taskName|like]"/></li>
						<li><label> 脚本内容 </label><input type="text" name="condition[scriptContent|like]"/></li>
						<li><label> 脚本类型 </label><input type="text" name="condition[scriptType|like]"/></li>
						<li>
							<a class="btn btn-success btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()">
	                <i class="fa fa-plus"></i> 新增
	            </a>
	            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()">
		            <i class="fa fa-edit"></i> 修改
		        </a>
				<a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()">
		            <i class="far fa-trash-alt"></i> 删除
		        </a>
		        <a class="btn btn-danger" onclick="$.operate.clean()">
	                <i class="fa fa-trash"></i> 清空
	            </a>
	            <a class="btn btn-warning" onclick="$.table.exportExcel()">
		            <i class="fa fa-download"></i> 导出
		        </a>
	        </div>

			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>

	<footer th:replace="dashboard/footer :: footer"></footer>

	<script>
		var prefix = ctx + "portal/auto/autoTask/" ;

		$(function() {
		    var options = {
		        url: prefix +"datatables" ,
		        createUrl: prefix + 'add' ,
		        updateUrl: prefix +"modify?id={id}" ,
		        changeStatusUrl: prefix +"changeStatus?id={id}" ,
		        cleanUrl: prefix + "clean",
		        detailUrl: prefix +"detail?id={id}",
		        removeUrl: prefix + "delete" ,
		        exportUrl: prefix + "export",
		        sortName: "operTime",
		        uniqueId:"id" ,
		        sortOrder: "desc",
                modalName: "",
		        escape: true,
		        showPageGo: true,
		        rememberSelected: true,
		        columns: [{field: 'state',checkbox: true },

					{field: 'runStatus', title: '运行状态', align: 'center', width:'100px', formatter:function(value,row,index){ 
				            var actions = [];
							if('1' === value){
					            actions.push('<a href="javascript:openLogger(\''+row.id+'\')">') ; 
				                actions.push('<img src="http://jenkins.linesno.com/static/f79a730d/images/48x48/blue_anime.gif" style="width: 18px;margin-bottom: 2px;"> ') ; 
				                actions.push('运行</a>') ; 
							}else{
				                actions.push('<img src="http://jenkins.linesno.com/static/f79a730d/images/16x16/blue.png" style="width: 18px;margin-bottom: 2px;"> ') ; 
					            actions.push('正常') ; 
							}
				            return actions.join('');
						}
					},
					{field: 'taskName', title: '任务名称'},
					{field: 'scriptType', title: '脚本类型'},
			        {field: 'addTime', title: '构建历史', align:'center' , width:'150px', formatter:function(value , row , index){
			        		return "查看" ; 
			     	   }
					},
					{field: 'taskVersion', title: '版本' , align:'center' , width:'150px', formatter:function(value , row , index){
		        			return "<a href='javascript:openLogger(\""+row.id+"\")'>"+value+"</a>" ; 
			     	   }
					},
					{field: 'taskVersion', title: '报告' , align:'center' , width:'150px', formatter:function(value , row , index){
		        			return "<a href='javascript:openReport(\""+row.id+"\")'>查看报告</a>" ; 
			     	   }
					},
					{field: 'lastSuccessTime', title: '最后成功时间'},
			        {field: 'id' , title: '操作', align: 'center', width:'250px', formatter: function(value, row, index) {
			                var actions = [];

			                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="runTask(\'' + row.id + '\')"><i class="fa fa-paper-plane"></i>运行</a> ');
			                /* 
			                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-edit"></i>代码</a> ');
			                */
			                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
			                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="far fa-trash-alt"></i>删除</a> ');

			                return actions.join('');
			          }
			     }]
		    };
		    $.table.init(options);
		});
	
		// 打开日志
		function openLogger(_id){
			$.modal.open('运行日志', ctx + "pages/portal/auto/autoTask/logger?taskId="+_id);	
		}
	
		// 查看报告 
		function openReport(_id){
			window.open(ctx + "portal/auto/autoTask/report?id="+_id , '_blank');	
		}
	
		// 运行任务
		function runTask(_id){
			console.log("_id = " + _id) ; 
			$.operate.get(ctx+"portal/auto/autoTask/runTask?id="+_id, null);
		}

	</script>
</body>
</html>

